package com.example.ivideo_2211a.commodity

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.example.ivideo_2211a.R

class MessageAdapter(private val context: Context, private val messages: List<Pair<String, Boolean>>) : BaseAdapter() {
    override fun getCount(): Int = messages.size
    override fun getItem(position: Int): Any = messages[position]
    override fun getItemId(position: Int): Long = position.toLong()

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val (msg, isUser) = messages[position]
        val view = convertView ?: LayoutInflater.from(context).inflate(
            if (isUser) R.layout.item_message_user else R.layout.item_message_service, parent, false
        )
        view.findViewById<TextView>(R.id.tv_message).text = msg
        return view
    }
}
